package com.withyou.euraka.provide.service;
import java.util.concurrent.ExecutionException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.withyou.euraka.provide.api.common.ResultVo;
import com.withyou.euraka.provide.api.common.message.detail.OrderMessage;
import com.withyou.euraka.provide.domain.Order;
import com.withyou.euraka.provide.factory.ResultVoFactory;
import com.withyou.euraka.provide.kfk.KafkaSender;

@Service
public class OrderService {

	@Autowired
	private KafkaSender kafkaSender;
	
	public ResultVo<Boolean> createOrder(Order order) throws InterruptedException, ExecutionException{
		//1.检验参数
		//2.保存数据库
		//3.发送消息
		sendOrderNotifyMessage(order);
		return ResultVoFactory.getSuccess();
	}
	
	
	private void sendOrderNotifyMessage(Order order) throws InterruptedException, ExecutionException{
		kafkaSender.sendOrderMessage(OrderMessage.builder().order(order).status("0").build());
	}
	
}
